/**
 * Created on 2007-03-06 22:08
 */
package game;

import java.awt.Color;

/**
 * @author David Wallin
 */
public class BasicMatris
{
	/**
	 * The height of this matris
	 */
	private int				m_Width;
	/**
	 * The width of this matris
	 */
	private int				m_Height;
	/**
	 * Information on each place in this miatris
	 */
	private boolean[]		m_PositionsState;
	/**
	 * The color of this matris
	 */
	private Color			m_Color;
	
	/**
	 * Constructor, initializes members
	 * 
	 * @param width The width of the matris to create 
	 * @param height The height of the matris to create
	 */
	public BasicMatris(int width, int height)
	{
		m_Width = width;
		m_Height = height;
		
		m_PositionsState = new boolean[width * height];
		
		for(int i = 0; i < (width * height); i++)
		{
			m_PositionsState[i] = false;
		}
		
		m_Color = Color.black;
	}
	
	public void setPosition(int x, int y, boolean state)
	{
		if((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height))
		{
			throw new IllegalArgumentException("x was " + x + ", allowed is 0 - " + (m_Width - 1) + "\ny was " + y + ", allowed is 0 - " +  (m_Height - 1));
		}
		
		m_PositionsState[((y * m_Width) + x)] = state;
	}
	
	public boolean getPosition(int x, int y)
	{
		if((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height))
		{
			throw new IllegalArgumentException("x was " + x + ", allowed is 0 - " + (m_Width - 1) + "\ny was " + y + ", allowed is 0 - " +  (m_Height - 1));
		}
		
		return m_PositionsState[((y * m_Width) + x)];
	}
	
	public int getWidth()
	{
		return m_Width;
	}
	
	public int getHeight()
	{
		return m_Height;
	}
	
	/**
	 * @return the m_Color
	 */
	public Color getColor()
	{
		return m_Color;
	}
	
	/**
	 * @param color the m_Color to set
	 */
	public void setColor(Color color)
	{
		m_Color = color;
	}
}
